/*
 * $Id$
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Copyright (c) $Date$ Rahel Ephrem. All Rights Reserved.
 *
 */

package model;
import java.util.ArrayList;
import java.util.List;
import controller.DataBaseInteactor;

/**
 * A Conference class that allows to create a conference and view a conference
 * as needed.
 * @author Rahel Ephrem
 * @version $Rev$ edited by Brendan Ng
 */
public class Conference {

	/**
	 * Name of a conference.
	 */
	private String name;
	
	/**
	 * due date for the conference.
	 */
	@SuppressWarnings("unused")
	private String date;

	/**
	 * the date of a paper must be submitted for the specific conference.
	 */
	private String manDate;
	
	/**
	 * a review due date.
	 */
	private String revDate;

	/**
	 * a recommendation due date.
	 */
	private String recDate;

	/**
	 * Location of the conference.
	 */
	@SuppressWarnings("unused")
	private String location;

	/**
	 * page limitation of the paper.
	 */
	@SuppressWarnings("unused")
	private int limitation;

	/**
	 * what language should the paper should be.
	 */
	@SuppressWarnings("unused")
	private String language;

	/**
	 * Program Chair of the conference.
	 */
	@SuppressWarnings("unused")
	private ProgramChair programChair;

	/**
	 * create object to access DataBaseInteactor class.
	 */
	private DataBaseInteactor interactor;

	/**
	 * 
	 * @param theConferenceName
	 * @param theConferenceDate
	 * @param theManDueDate
	 * @param theRecDueDate
	 * @param theReviewDueDate
	 * @param theProgramChair
	 */
	public Conference(final String theConferenceName,
			final String theConferenceDate, final String theManDueDate,
			final String theRecDueDate, final String theReviewDueDate,
			final ProgramChair theProgramChair, final DataBaseInteactor theInteractor) {
		name = theConferenceName;
		date = theConferenceDate;
		manDate = theManDueDate;
		recDate = theRecDueDate;
		revDate = theReviewDueDate;
		programChair = theProgramChair;
		interactor = theInteractor;

	createConference(theConferenceName, theConferenceDate, theManDueDate,
			theRecDueDate, theReviewDueDate, theProgramChair);
	}

	/**
	 * Creates a conference with the given name. All other fields are not
	 * initialized.
	 * @param theName The name
	 * @param theInteractor accessor for DataBaseInteactor database class.
	 */
	public Conference(final String theName, DataBaseInteactor theInteractor) {
		name = theName;
		interactor = theInteractor;
	}

	/**
	 * Empty contractor that allows a user to create an object for conference
	 * class with out updating the database.
	 * @param theInteractor with data base accessor object
	 */
	public Conference(DataBaseInteactor theInteractor) {
		interactor = theInteractor;
	}

	/**
	 * update the database after a user creates a conference.
	 * @param theConferenceName conference name
	 * @param theConferenceDate the conference expiration date
	 * @param theManDueDate the manuscript due date
	 * @param theRecDueDate the recommendation due date
	 * @param theReviewDueDate the review due date
	 * @param theProgramChair the program chair decision due date
	 */
	public void createConference(final String theConferenceName,
			final String theConferenceDate, final String theManDueDate,
			final String theRecDueDate, final String theReviewDueDate,
			final ProgramChair theProgramChair) {
		interactor.makeConference(theConferenceName, theConferenceDate,
						theManDueDate, theRecDueDate, theReviewDueDate,
						theProgramChair);

	}

	/**
	 * Set the name of the conference.
	 * @param theName The name
	 */
	public void setName(String theName) {
		name = theName;
	}
	

	/**
	 * return the name of the conference.
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * Get a list of every conference.
	 * @return A list of every conference
	 */
	public List<Conference> getConferences() {
		List<Conference> confList = new ArrayList<Conference>();
		List<String> name = interactor.getConferenceTitles();
		List<String> date = interactor.getConferenceDates();
		List<String> manDate = interactor.getConferenceManDates();
		List<String> recDate = interactor.getConferenceRecDates();
		List<String> revDate = interactor.getConferenceRevDates();
		List<String> pcUN = interactor.getConferenceProgramChairUN();
		List<String> pcP = interactor.getConferenceProgramChairPW();
		
		//check if the list is not empty before going through the loop.
		if (name.size() == 0) {
			throw new NullPointerException("The list is empty");
		}
		else {
		for (int i = 0; i < name.size(); i++) {
			confList.add(new Conference(name.get(i), date.get(i), manDate.get(i),
					recDate.get(i), revDate.get(i), new ProgramChair(
					pcUN.get(i), interactor), interactor));
		}
	}

		return confList;
	}

	/**
	 * return due date of a conference.
	 * @return due date
	 */
	public String getManDate() {
		return manDate;
	}

	/**
	 * Set the expiration date for the conference.
	 * @param manDate due date
	 */
	public void setManDate(String manDate) {
		this.manDate = manDate;
	}

	/**
	 * return due date of a recommendation.
	 * 
	 * @return due date
	 */
	public String getRecomDate() {
		return recDate;
	}

	/**
	 * Set the expiration date for the recommendation.
	 * @param recomDate due date
	 */
	public void setRecomDate(String recomDate) {
		recDate = recomDate;
	}

	/**
	 * return due date of a review.
	 * @return due date
	 */
	public String getreviewDate() {
		return revDate;
	}

	/**
	 * Set the expiration date for the review.
	 * @param reviwDate due date
	 */
	public void setreviewDate(String reviewDate) {
		revDate = reviewDate;
	}

	/**
	 * Adds the Document to the Conference.
	 * @param conf the name of the conference the document will be added to.
	 * @param theDocument to be added to the list of Conference papers.
	 */
	public void setManuscript(final Author theAuthor, final Conference conf,
			final Manuscript theDocument) {
		interactor.submitManuscript(theAuthor, conf, theDocument);
	}

	/**
	 * A basic getter for Documents submitted to the Conference.
	 * @param the name of the conference.
	 * @param documentID of the Document to retrieve.
	 * @return the requested Document.
	 */
	public String getManuscript(final Author theAuthor, final Conference conf,
			final String documentID) {
		return interactor.getManuscriptContents(theAuthor, conf, documentID);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		return name;
	}
}
